import { EntitySceneFactory } from "../../../../../Core/Module/Entity/EntitySceneFactory";
import { Scene } from "../../../../../Core/Module/Entity/Scene";
import { SceneType } from "../../../../../Core/Module/Entity/SceneType";
import { EventSystem } from "../../../../../Core/Module/EventSystem/EventSystem";
import { ETTask } from "../../../../../Support/Share/Lib/Async/ETTask";
import { PlayerComponent } from "../../../../Model/Client/Demo/Unit/PlayerComponent";
import { EventType } from "../../../../Model/Share/Demo/EventType";
import { ObjectWait } from "../../../../Model/Share/Module/ObjectWait/ObjectWait";
import { ClientSceneManagerComponent } from "../../../../Model/Share/Module/Scene/ClientSceneManagerComponent";
import { CurrentScenesComponent } from "../../../../Model/Share/Module/Scene/CurrentScenesComponent";
import { UnitManagerComponent } from "../../../../Model/Share/Module/Unit/UnitManagerComponent";
import { LocalStorageComponent } from "../../../../ModelView/Client/Module/LocalStorage/LocalStorageComponent";

export class SceneFactory {

    public static async CreateClientScene(zone: number, name: string): Promise<Scene> {
        await ETTask.CompletedTask;
        let clientScene = EntitySceneFactory.CreateScene(zone, SceneType.Client, name, ClientSceneManagerComponent.Instance);
        clientScene.AddComponent<CurrentScenesComponent>(CurrentScenesComponent);
        clientScene.AddComponent<ObjectWait>(ObjectWait);
        clientScene.AddComponent<PlayerComponent>(PlayerComponent);
        clientScene.AddComponent<LocalStorageComponent>(LocalStorageComponent);
        clientScene.AddComponent<UnitManagerComponent>(UnitManagerComponent);

        let afterCreateClientScene = new EventType.AfterCreateClientScene();
        afterCreateClientScene.ZoneScene = clientScene;
        EventSystem.Instance.Publish(clientScene, afterCreateClientScene);
        return clientScene;
    }

    public static CreateCurrentScene(id: number, zone: number, name: string, currentScenesComponent: CurrentScenesComponent): Scene {
        let currentScene = EntitySceneFactory.CreateSceneWithInstanceId(id, zone, SceneType.Current, name, currentScenesComponent);
        currentScenesComponent.Scene = currentScene;

        let afterCreateCurrentScene = new EventType.AfterCreateCurrentScene();
        afterCreateCurrentScene.CurrentScene = currentScene;
        EventSystem.Instance.Publish(currentScene, afterCreateCurrentScene);
        return currentScene;
    }

}